package com.study.rpc09;

import com.caucho.hessian.io.Hessian2Output;
import com.study.common.User;

import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;

public class HessianVSJDK {

    public static void main(String[] args) throws Exception{
        User u = new User(1, "zhangsan");
        System.out.println("hessian: " + hessianSerialize(u).length);
        System.out.println("jdk: " + jdkSerialize(u).length);
    }

    public static byte[] hessianSerialize(Object o) throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Hessian2Output output = new Hessian2Output(baos);
        output.writeObject(o);
        output.flush();
        byte[] bytes = baos.toByteArray();
        baos.close();
        output.close();
        return bytes;
    }

    public static byte[] jdkSerialize(Object o) throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream output = new ObjectOutputStream(baos);
        output.writeObject(o);
        output.flush();
        byte[] bytes = baos.toByteArray();
        baos.close();
        output.close();
        return bytes;
    }



}


